<?php

/**
 * VehicleModel
 */
//include 'CategoryModel.php';
include_once 'Application/Models/CategoryModel.php';
include_once 'Application/Views/vehicle/VehicleView.php';
class Application_Models_VehicleModel{ 
    private $_idLicensePlate;
    private $_idCategory;    
    private $_vehicleSeries;
    private $_stamp;
    private $_vehicleModel;
    
    function __construct($_idCategory ) {
        $_idCategory=new Application_Models_CategoryModel();
        
    }
    
    public function get_idLicensePlate() {
        return $this->_idLicencePlate;
    }

    public function set_idLicensePlate($_idLicensePlate) {
        $this->_idLicensePlate = $_idLicensePlate;
    }

    public function get_idCategory() {
        return $this->_idCategory;
    }

    public function set_idCategory($_idCategory) {
        $this->_idCategory = $_idCategory;
    }

    public function get_vehicleSeries() {
        return $this->_vehicleSeries;
    }

    public function set_vehicleSeries($_vehicleSeries) {
        $this->_vehicleSeries = $_vehicleSeries;
    }

    public function get_stamp() {
        return $this->_stamp;
    }

    public function set_stamp($_stamp) {
        $this->_stamp = $_stamp;
    }

    public function get_vehicleModel() {
        return $this->_vehicleModel;
    }

    public function set_vehicleModel($_vehicleModel) {
        $this->_vehicleModel = $_vehicleModel;
    }

    /**
     * registrar
     * 
     */
    
    public function insertVehicle(){
        global $config;                  
        $objDb=new Class_Db();
        $objDb->selectManager()->connect();

        $columns="'"."$this->_idLicensePlate"."','"."$this->_idCategory"."','"."$this->_vehicleSeries".
                "','"."$this->_stamp"."','"."$this->_vehicleModel"."'";
        //die($columns);
        $table=$config['tableVehicle'];
        $consult=$objDb->selectManager()->insertAdd(strtoupper($columns), $table);
        $viewVehicle=new Application_Views_VehicleView();
        if($consult){            
            //echo "si se pudo";
            header("Location: principal.php?action=show&controller=Vehicle");
        }else{
            $viewVehicle->formListVehicle('no se pudo');
        }
        
    }
    
    public static function showVehicle(){
        global $config;
        
        $objDb=new Class_Db();
        $objDb->selectManager()->connect();

        $table=$config['tableVehicle'];        
        $columns="*";
        $consult=$objDb->selectManager()->selectAdd($columns, $table);
        $viewVehicle=new Application_Views_VehicleView();          
        $viewVehicle->showVehicle($consult);
    }
    
    /**
     * actualizar
     * 
    */ 
    public function updateVehicle(){
        global $config;
        
        $objDb=new Class_Db();
        $objDb->selectManager()->connect();

        $table=$config['tableVehicle'];
        $columns="'"."$this->_idCategory"."','"."$this->_vehicleSeries"."','".
                "$this->_stamp"."','"."$this->_vehicleModel"."'";
        $condition="'$this->_idLicensePlate'";
        
        $query="update $table set id_categoria='".$this->_idCategory."',serie_vehiculo='".$this->_vehicleSeries."',
            marca='".$this->_stamp."',modelo='".$this->_vehicleModel."' where id_placa= ".$condition."";
        //die(strtoupper($query));
        //$consult=$objDb->selectManager()->updateAdd($columns, $table, $condition);     
        $consult=$objDb->selectManager()->update(strtoupper($query));
        $viewVehicle=new Application_Views_VehicleView();
        
        if($consult){
            //echo 'modificado con exito';ESTO NO REDIRIGE A LISTAR
            header("Location: principal.php?action=show&controller=Vehicle");
        }else{
            $viewVehicle->formListVehicle('algo anda mal');
        }
    }
}